<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //创建一个Promise对象
        const p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('获取到用户数据!');
            }, 1000);
        })

        //调用then方法 then方法的返回结果是Promise对象,对象状态由回调函数的执行结果决定
        //1.如何回调函数的返回结果是非 Pormise类型属性，状态为成功，返回值为对象成功的值
        const result = p.then((value) => {
            console.log(value); //resolved/fulfilled
            //1.非Promise 类型的属性
            // return '成功';

            //2.是 Promse 类型的属性
           /*  return new Promise((resolve, reject) => {
                // resolve('ok');
                reject('error');
            }); */

            //3.抛出错误
            throw new Error('出错了!');
        }, (reason) => {
           console.error('出错了!!!');
        })
        console.log(result);
    </script>
</body>
</html>